package cn.zh.listener;

import cn.zh.dto.OptLogDTO;
import cn.zh.event.SysLogEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 系统日志监听器
 *
 * @author 白羊
 * @date 2021/12/29
 */
@Component
public class SysLogListener {

    @Async//异步处理
    @EventListener(SysLogEvent.class)
    public void saveLog(SysLogEvent sysLogEvent){
        OptLogDTO source = (OptLogDTO) sysLogEvent.getSource();
        long id = Thread.currentThread().getId();
        System.out.println("监听到日志操作事件：" + source + " 线程id：" + id);
        //将日志信息保存到数据库...
    }
}
